home *** CD-ROM | disk | FTP | other *** search
/ Aminet 34 / Aminet 34 (2000)(Schatztruhe)[!][Dec 1999].iso / Aminet / util / misc / cycledbase.lha / CycleDBase / CycleDBaseWindow.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-09-27  |  26.2 KB  |  508 lines

  1. /* Window.c */
  2. /* File contains functions for controlling the program including the
  3. main program loop */
  4.  
  5. #include <exec/types.h>
  6. #include <exec/memory.h>
  7. #include <clib/asl_protos.h>
  8. #include <clib/dos_protos.h>
  9. #include <clib/exec_protos.h>
  10. #include <clib/intuition_protos.h>
  11. #include <clib/gadtools_protos.h>
  12. #include <clib/graphics_protos.h>
  13. #include <graphics/gfxmacros.h>
  14. #include <graphics/GfxBase.h>
  15. #include <intuition/intuition.h>
  16. #include <intuition/IntuitionBase.h>
  17. #include <libraries/asl.h>
  18. #include <libraries/dos.h>
  19. #include <libraries/gadtools.h>
  20. #include <string.h>
  21. #include <stdlib.h>
  22. #include <stdio.h>
  23.  
  24. #include "Search.c"
  25.  
  26. struct TagItem frtags[] =
  27. {
  28.     ASLFR_TitleText,         (ULONG)"CycleDataBase File Requester",
  29.     ASLFR_InitialHeight,     MYHEIGHT,
  30.     ASLFR_InitialWidth,      MYWIDTH,
  31.     ASLFR_InitialLeftEdge,   MYLEFTEDGE,
  32.     ASLFR_InitialTopEdge,    MYTOPEDGE,
  33.     ASLFR_PositiveText,      (ULONG)"Okay",
  34.     ASLFR_NegativeText,      (ULONG)"Cancel",
  35.     ASLFR_InitialFile,       (ULONG)".cdb",
  36.     TAG_DONE
  37. };
  38.  
  39. /*
  40. ** Function for loading the database from a file.
  41. */
  42. // Removed for copyright reasons
  43.  
  44. /*
  45. ** Function for saving the database to a file.
  46. */
  47. // Removed for copyright reasons
  48.  
  49. /*
  50. ** Function for defining and displaying About Alert message.
  51. */
  52. void about_alert()
  53. {
  54.     char message[160];
  55.  
  56.     strcpy(message, "   Cycle Database program created by Donald W Millican.");
  57.     strcat(message,
  58.           "     (C) Copyright 1999 DWM Productions.");
  59.     strcat(message,
  60.           "     Version 1.95 26/09/99. Press Left Mouse Button to continue.");
  61.  
  62.     message[0]=0;       /* X position of the first string */
  63.     message[1]=32;      /*               - " -            */
  64.     message[2]=16;      /* Y             - " -            */
  65.  
  66.     message[55]='\0';   /* NULL sign which finish of the first string. */
  67.     message[56]=TRUE;   /* Continuation byte set to TRUE (new string). */
  68.  
  69.     message[57]=0;
  70.     message[58]=32;
  71.     message[59]=32;
  72.  
  73.     message[95]='\0';
  74.     message[96]=TRUE;
  75.  
  76.     message[97]=0;      /* X position of the third string. */
  77.     message[98]=32;     /*               - " -             */
  78.     message[99]=48;     /* Y             - " -             */
  79.  
  80.     message[158]='\0';  /* NULL sign which finish of the third string.   */
  81.     message[159]=FALSE; /* Continuation byte set to FALSE (last string). */
  82.  
  83.     /* We will now display the Alert message: */
  84.     DisplayAlert( RECOVERY_ALERT, message, 64 );
  85. }
  86.  
  87. /*
  88. ** Standard message handling loop with GadTools message handling functions
  89. ** used (GT_GetIMsg() and GT_ReplyIMsg()).
  90. */
  91. void process_window_events(struct Screen *mysc, struct Window *mywin,
  92.     struct Gadget *my_gads[], struct Menu *mainmenustrip, struct StringInfo *gad_ptr[])
  93. {
  94.     struct IntuiMessage *imsg;
  95.     ULONG imsgClass;
  96.     UWORD imsgCode;
  97.     BOOL terminated = FALSE;
  98.     struct Gadget *gad;
  99.     UWORD menu_number, which_menu, which_item;
  100.     MenuItem *item;
  101.     BOOL cont = FALSE;
  102.     BOOL move_record = FALSE;
  103.     BOOL destdate = FALSE;
  104.     UBYTE *data_entered;
  105.     char sentence[DESTLENGTH];
  106.     char datetemp[DATELENGTH];
  107. //    char desttemp[DESTLENGTH];
  108.     int index = 0, count, direction = 0;
  109. //    int count2, count3;
  110.     char space[DESTLENGTH], space2[DATELENGTH];
  111.     long take_train = 0;
  112.     long number = 0;
  113.     int result, answer = 0, length = 0, matchcount = 0;
  114.     BOOL record_found = FALSE;
  115.     int position = 0, matches = 0;
  116.     // Pointers for Containing search
  117. //    int start, next;
  118.  
  119.     data_entered = (UBYTE *)sentence;
  120.  
  121.     // Clear arrays used in menu item 'New'
  122.     for(count=0; count<DESTLENGTH; count++)
  123.         space[count] = '\0';
  124.     for(count=0; count<DATELENGTH; count++)
  125.         space2[count] = '\0';
  126.  
  127. while (!terminated)
  128.     {
  129.     Wait (1 << mywin->UserPort->mp_SigBit);
  130.  
  131.     /* GT_GetIMsg() returns an IntuiMessage with more friendly information for
  132.     ** complex gadget classes.  Use it wherever you get IntuiMessages where
  133.     ** using GadTools gadgets.
  134.     */
  135.  
  136.     while ((!terminated) &&
  137.            (imsg = GT_GetIMsg(mywin->UserPort)))
  138.         {
  139.         /* Presuming a gadget, of course, but no harm...
  140.         ** Only dereference this value (gad) where the Class specifies
  141.         ** that it is a gadget event.
  142.         */
  143.         gad = (struct Gadget *)imsg->IAddress;
  144.  
  145.         imsgClass = imsg->Class;
  146.         imsgCode = imsg->Code;
  147.         menu_number = imsg->Code;
  148.  
  149.         /* Use the toolkit message-replying function here... */
  150.         GT_ReplyIMsg(imsg);
  151.  
  152.         switch (imsgClass)
  153.             {
  154.             /*  --- WARNING --- WARNING --- WARNING --- WARNING --- WARNING ---
  155.             ** GadTools puts the gadget address into IAddress of IDCMP_MOUSEMOVE
  156.             ** messages.  This is NOT true for standard Intuition messages,
  157.             ** but is an added feature of GadTools.
  158.             */
  159.             case IDCMP_VANILLAKEY:
  160.                 cont = handleVanillaKey(mywin, imsgCode, my_gads, index, direction);
  161.                 if(cont == TRUE)
  162.                 {
  163.                     if(direction < 0)
  164.                     {
  165.                         // Go back one record
  166.                         if(index > 0)
  167.                         {
  168.                             index--;
  169.                             // Load new gadget values
  170.                             GT_SetGadgetAttrs(my_gads[MYGAD_RECCOUNT], mywin, NULL, GTNM_Number, index+1, TAG_END);
  171.                             GT_SetGadgetAttrs(my_gads[MYGAD_DESTGAD], mywin, NULL, GTST_String, cycledata[index].destination, TAG_END);
  172.                             GT_SetGadgetAttrs(my_gads[MYGAD_DATEGAD], mywin, NULL, GTST_String, cycledata[index].date, TAG_END);
  173.                             GT_SetGadgetAttrs(my_gads[MYGAD_DIST1], mywin, NULL, GTIN_Number, cycledata[index].cycledist1, TAG_END);
  174.                             GT_SetGadgetAttrs(my_gads[MYGAD_DIST2], mywin, NULL, GTIN_Number, cycledata[index].cycledist2, TAG_END);
  175.                             GT_SetGadgetAttrs(my_gads[MYGAD_CYCLEOUTH], mywin, NULL, GTIN_Number, cycledata[index].cycleouth, TAG_END);
  176.                             GT_SetGadgetAttrs(my_gads[MYGAD_CYCLEOUTM], mywin, NULL, GTIN_Number, cycledata[index].cycleoutm, TAG_END);
  177.                             GT_SetGadgetAttrs(my_gads[MYGAD_CYCLEBACKH], mywin, NULL, GTIN_Number, cycledata[index].cyclebackh, TAG_END);
  178.                             GT_SetGadgetAttrs(my_gads[MYGAD_CYCLEBACKM], mywin, NULL, GTIN_Number, cycledata[index].cyclebackm, TAG_END);
  179.                             GT_SetGadgetAttrs(my_gads[MYGAD_TRAINTICK], mywin, NULL, GTCB_Checked, cycledata[index].train, TAG_END);
  180.                             GT_SetGadgetAttrs(my_gads[MYGAD_TRAINOUTH], mywin, NULL, GTIN_Number, cycledata[index].trainouth, TAG_END);
  181.                             GT_SetGadgetAttrs(my_gads[MYGAD_TRAINOUTM], mywin, NULL, GTIN_Number, cycledata[index].trainoutm, TAG_END);
  182.                             GT_SetGadgetAttrs(my_gads[MYGAD_TRAINBACKH], mywin, NULL, GTIN_Number, cycledata[index].trainbackh, TAG_END);
  183.                             GT_SetGadgetAttrs(my_gads[MYGAD_TRAINBACKM], mywin, NULL, GTIN_Number, cycledata[index].trainbackm, TAG_END);
  184.                             GT_SetGadgetAttrs(my_gads[MYGAD_TOTTIMEH], mywin, NULL, GTIN_Number, cycledata[index].totalh, TAG_END);
  185.                             GT_SetGadgetAttrs(my_gads[MYGAD_TOTTIMEM], mywin, NULL, GTIN_Number, cycledata[index].totalm, TAG_END);
  186.                         }
  187.                     }
  188.                     if(direction > 0)
  189.                     {
  190.                         // Go forward one record
  191.                         if(index < TRIPS-1)
  192.                         {
  193.                             index++;
  194.                             // Load new gadget values
  195.                             GT_SetGadgetAttrs(my_gads[MYGAD_RECCOUNT], mywin, NULL, GTNM_Number, index+1, TAG_END);
  196.                             GT_SetGadgetAttrs(my_gads[MYGAD_DESTGAD], mywin, NULL, GTST_String, cycledata[index].destination, TAG_END);
  197.                             GT_SetGadgetAttrs(my_gads[MYGAD_DATEGAD], mywin, NULL, GTST_String, cycledata[index].date, TAG_END);
  198.                             GT_SetGadgetAttrs(my_gads[MYGAD_DIST1], mywin, NULL, GTIN_Number, cycledata[index].cycledist1, TAG_END);
  199.                             GT_SetGadgetAttrs(my_gads[MYGAD_DIST2], mywin, NULL, GTIN_Number, cycledata[index].cycledist2, TAG_END);
  200.                             GT_SetGadgetAttrs(my_gads[MYGAD_CYCLEOUTH], mywin, NULL, GTIN_Number, cycledata[index].cycleouth, TAG_END);
  201.                             GT_SetGadgetAttrs(my_gads[MYGAD_CYCLEOUTM], mywin, NULL, GTIN_Number, cycledata[index].cycleoutm, TAG_END);
  202.                             GT_SetGadgetAttrs(my_gads[MYGAD_CYCLEBACKH], mywin, NULL, GTIN_Number, cycledata[index].cyclebackh, TAG_END);
  203.                             GT_SetGadgetAttrs(my_gads[MYGAD_CYCLEBACKM], mywin, NULL, GTIN_Number, cycledata[index].cyclebackm, TAG_END);
  204.                             GT_SetGadgetAttrs(my_gads[MYGAD_TRAINTICK], mywin, NULL, GTCB_Checked, cycledata[index].train, TAG_END);
  205.                             GT_SetGadgetAttrs(my_gads[MYGAD_TRAINOUTH], mywin, NULL, GTIN_Number, cycledata[index].trainouth, TAG_END);
  206.                             GT_SetGadgetAttrs(my_gads[MYGAD_TRAINOUTM], mywin, NULL, GTIN_Number, cycledata[index].trainoutm, TAG_END);
  207.                             GT_SetGadgetAttrs(my_gads[MYGAD_TRAINBACKH], mywin, NULL, GTIN_Number, cycledata[index].trainbackh, TAG_END);
  208.                             GT_SetGadgetAttrs(my_gads[MYGAD_TRAINBACKM], mywin, NULL, GTIN_Number, cycledata[index].trainbackm, TAG_END);
  209.                             GT_SetGadgetAttrs(my_gads[MYGAD_TOTTIMEH], mywin, NULL, GTIN_Number, cycledata[index].totalh, TAG_END);
  210.                             GT_SetGadgetAttrs(my_gads[MYGAD_TOTTIMEM], mywin, NULL, GTIN_Number, cycledata[index].totalm, TAG_END);
  211.                         }
  212.                     }
  213.                 }
  214.                 break;
  215.             case IDCMP_GADGETUP:
  216.                 move_record = handleGadgetEvent(mysc, mywin, gad, imsgCode, my_gads);
  217.  
  218.                 if(move_record == TRUE)
  219.                 {
  220.                     if(gad->GadgetID == MYGAD_PREVIOUS)
  221.                     {
  222.                         if(index > 0)
  223.                         {
  224.                             index--;
  225.                             // Load new gadget values
  226.                             GT_SetGadgetAttrs(my_gads[MYGAD_RECCOUNT], mywin, NULL, GTNM_Number, index+1, TAG_END);
  227.                             GT_SetGadgetAttrs(my_gads[MYGAD_DESTGAD], mywin, NULL, GTST_String, cycledata[index].destination, TAG_END);
  228.                             GT_SetGadgetAttrs(my_gads[MYGAD_DATEGAD], mywin, NULL, GTST_String, cycledata[index].date, TAG_END);
  229.                             GT_SetGadgetAttrs(my_gads[MYGAD_DIST1], mywin, NULL, GTIN_Number, cycledata[index].cycledist1, TAG_END);
  230.                             GT_SetGadgetAttrs(my_gads[MYGAD_DIST2], mywin, NULL, GTIN_Number, cycledata[index].cycledist2, TAG_END);
  231.                             GT_SetGadgetAttrs(my_gads[MYGAD_CYCLEOUTH], mywin, NULL, GTIN_Number, cycledata[index].cycleouth, TAG_END);
  232.                             GT_SetGadgetAttrs(my_gads[MYGAD_CYCLEOUTM], mywin, NULL, GTIN_Number, cycledata[index].cycleoutm, TAG_END);
  233.                             GT_SetGadgetAttrs(my_gads[MYGAD_CYCLEBACKH], mywin, NULL, GTIN_Number, cycledata[index].cyclebackh, TAG_END);
  234.                             GT_SetGadgetAttrs(my_gads[MYGAD_CYCLEBACKM], mywin, NULL, GTIN_Number, cycledata[index].cyclebackm, TAG_END);
  235.                             GT_SetGadgetAttrs(my_gads[MYGAD_TRAINTICK], mywin, NULL, GTCB_Checked, cycledata[index].train, TAG_END);
  236.                             GT_SetGadgetAttrs(my_gads[MYGAD_TRAINOUTH], mywin, NULL, GTIN_Number, cycledata[index].trainouth, TAG_END);
  237.                             GT_SetGadgetAttrs(my_gads[MYGAD_TRAINOUTM], mywin, NULL, GTIN_Number, cycledata[index].trainoutm, TAG_END);
  238.                             GT_SetGadgetAttrs(my_gads[MYGAD_TRAINBACKH], mywin, NULL, GTIN_Number, cycledata[index].trainbackh, TAG_END);
  239.                             GT_SetGadgetAttrs(my_gads[MYGAD_TRAINBACKM], mywin, NULL, GTIN_Number, cycledata[index].trainbackm, TAG_END);
  240.                             GT_SetGadgetAttrs(my_gads[MYGAD_TOTTIMEH], mywin, NULL, GTIN_Number, cycledata[index].totalh, TAG_END);
  241.                             GT_SetGadgetAttrs(my_gads[MYGAD_TOTTIMEM], mywin, NULL, GTIN_Number, cycledata[index].totalm, TAG_END);
  242.                         }
  243.                     }
  244.                     if(gad->GadgetID == MYGAD_NEXT)
  245.                     {
  246.                         if(index < TRIPS-1)
  247.                         {
  248.                             index++;
  249.                             // Load new gadget values
  250.                             GT_SetGadgetAttrs(my_gads[MYGAD_RECCOUNT], mywin, NULL, GTNM_Number, index+1, TAG_END);
  251.                             GT_SetGadgetAttrs(my_gads[MYGAD_DESTGAD], mywin, NULL, GTST_String, cycledata[index].destination, TAG_END);
  252.                             GT_SetGadgetAttrs(my_gads[MYGAD_DATEGAD], mywin, NULL, GTST_String, cycledata[index].date, TAG_END);
  253.                             GT_SetGadgetAttrs(my_gads[MYGAD_DIST1], mywin, NULL, GTIN_Number, cycledata[index].cycledist1, TAG_END);
  254.                             GT_SetGadgetAttrs(my_gads[MYGAD_DIST2], mywin, NULL, GTIN_Number, cycledata[index].cycledist2, TAG_END);
  255.                             GT_SetGadgetAttrs(my_gads[MYGAD_CYCLEOUTH], mywin, NULL, GTIN_Number, cycledata[index].cycleouth, TAG_END);
  256.                             GT_SetGadgetAttrs(my_gads[MYGAD_CYCLEOUTM], mywin, NULL, GTIN_Number, cycledata[index].cycleoutm, TAG_END);
  257.                             GT_SetGadgetAttrs(my_gads[MYGAD_CYCLEBACKH], mywin, NULL, GTIN_Number, cycledata[index].cyclebackh, TAG_END);
  258.                             GT_SetGadgetAttrs(my_gads[MYGAD_CYCLEBACKM], mywin, NULL, GTIN_Number, cycledata[index].cyclebackm, TAG_END);
  259.                             GT_SetGadgetAttrs(my_gads[MYGAD_TRAINTICK], mywin, NULL, GTCB_Checked, cycledata[index].train, TAG_END);
  260.                             GT_SetGadgetAttrs(my_gads[MYGAD_TRAINOUTH], mywin, NULL, GTIN_Number, cycledata[index].trainouth, TAG_END);
  261.                             GT_SetGadgetAttrs(my_gads[MYGAD_TRAINOUTM], mywin, NULL, GTIN_Number, cycledata[index].trainoutm, TAG_END);
  262.                             GT_SetGadgetAttrs(my_gads[MYGAD_TRAINBACKH], mywin, NULL, GTIN_Number, cycledata[index].trainbackh, TAG_END);
  263.                             GT_SetGadgetAttrs(my_gads[MYGAD_TRAINBACKM], mywin, NULL, GTIN_Number, cycledata[index].trainbackm, TAG_END);
  264.                             GT_SetGadgetAttrs(my_gads[MYGAD_TOTTIMEH], mywin, NULL, GTIN_Number, cycledata[index].totalh, TAG_END);
  265.                             GT_SetGadgetAttrs(my_gads[MYGAD_TOTTIMEM], mywin, NULL, GTIN_Number, cycledata[index].totalm, TAG_END);
  266.                         }
  267.                     }
  268.                 }
  269.                 if(gad->GadgetID == MYGAD_DESTGAD)
  270.                 {
  271.                     // Copy text from string gadget to working variable
  272.                     strcpy(data_entered, gad_ptr[0]->Buffer);
  273.                     strcpy(cycledata[index].destination, data_entered);
  274.                     // Set changed BOOL to TRUE
  275.                     cycledata[index].changed = TRUE;
  276.                     // recs = Go through all recs and count no of TRUE's
  277.                     records.recs[0] = 0;
  278.                     for(count=0; count<TRIPS-1; count++)
  279.                     {
  280.                         if(cycledata[count].changed == TRUE)
  281.                             records.recs[0]++;
  282.                     }
  283.                 }
  284.                 if(gad->GadgetID == MYGAD_DATEGAD)
  285.                 {
  286.                     // Copy text from string gadget to working variable
  287.                     strcpy(data_entered, gad_ptr[1]->Buffer);
  288.                     strcpy(cycledata[index].date, data_entered);
  289.                 }
  290.                 if(gad->GadgetID == MYGAD_DIST1)
  291.                 {
  292.                     GT_GetGadgetAttrs(my_gads[MYGAD_DIST1], mywin, NULL, GTIN_Number, &number, TAG_END);
  293.                     cycledata[index].cycledist1 = number;
  294.                 }
  295.                 if(gad->GadgetID == MYGAD_DIST2)
  296.                 {
  297.                     GT_GetGadgetAttrs(my_gads[MYGAD_DIST2], mywin, NULL, GTIN_Number, &number, TAG_END);
  298.                     cycledata[index].cycledist2 = number;
  299.                 }
  300.                 if(gad->GadgetID == MYGAD_CYCLEOUTH)
  301.                 {
  302.                     GT_GetGadgetAttrs(my_gads[MYGAD_CYCLEOUTH], mywin, NULL, GTIN_Number, &number, TAG_END);
  303.                     cycledata[index].cycleouth = number;
  304.                 }
  305.                 if(gad->GadgetID == MYGAD_CYCLEOUTM)
  306.                 {
  307.                     GT_GetGadgetAttrs(my_gads[MYGAD_CYCLEOUTM], mywin, NULL, GTIN_Number, &number, TAG_END);
  308.                     cycledata[index].cycleoutm = number;
  309.                 }
  310.                 if(gad->GadgetID == MYGAD_CYCLEBACKH)
  311.                 {
  312.                     GT_GetGadgetAttrs(my_gads[MYGAD_CYCLEBACKH], mywin, NULL, GTIN_Number, &number, TAG_END);
  313.                     cycledata[index].cyclebackh = number;
  314.                 }
  315.                 if(gad->GadgetID == MYGAD_CYCLEBACKM)
  316.                 {
  317.                     GT_GetGadgetAttrs(my_gads[MYGAD_CYCLEBACKM], mywin, NULL, GTIN_Number, &number, TAG_END);
  318.                     cycledata[index].cyclebackm = number;
  319.                 }
  320.                 if(gad->GadgetID == MYGAD_TRAINTICK)
  321.                 {
  322.                     GT_GetGadgetAttrs(my_gads[MYGAD_TRAINTICK], mywin, NULL, GTCB_Checked, &take_train, TAG_END);
  323.                     if(take_train == 1)
  324.                         cycledata[index].train = TRUE;
  325.                     else
  326.                         cycledata[index].train = FALSE;
  327.                 }
  328.                 if(gad->GadgetID == MYGAD_TRAINOUTH)
  329.                 {
  330.                     GT_GetGadgetAttrs(my_gads[MYGAD_TRAINOUTH], mywin, NULL, GTIN_Number, &number, TAG_END);
  331.                     cycledata[index].trainouth = number;
  332.                 }
  333.                 if(gad->GadgetID == MYGAD_TRAINOUTM)
  334.                 {
  335.                     GT_GetGadgetAttrs(my_gads[MYGAD_TRAINOUTM], mywin, NULL, GTIN_Number, &number, TAG_END);
  336.                     cycledata[index].trainoutm = number;
  337.                 }
  338.                 if(gad->GadgetID == MYGAD_TRAINBACKH)
  339.                 {
  340.                     GT_GetGadgetAttrs(my_gads[MYGAD_TRAINBACKH], mywin, NULL, GTIN_Number, &number, TAG_END);
  341.                     cycledata[index].trainbackh = number;
  342.                 }
  343.                 if(gad->GadgetID == MYGAD_TRAINBACKM)
  344.                 {
  345.                     GT_GetGadgetAttrs(my_gads[MYGAD_TRAINBACKM], mywin, NULL, GTIN_Number, &number, TAG_END);
  346.                     cycledata[index].trainbackm = number;
  347.                 }
  348.                if(gad->GadgetID == MYGAD_TOTTIMEH)
  349.                 {
  350.                     GT_GetGadgetAttrs(my_gads[MYGAD_TOTTIMEH], mywin, NULL, GTIN_Number, &number, TAG_END);
  351.                     cycledata[index].totalh = number;
  352.                 }
  353.                 if(gad->GadgetID == MYGAD_TOTTIMEM)
  354.                 {
  355.                     GT_GetGadgetAttrs(my_gads[MYGAD_TOTTIMEM], mywin, NULL, GTIN_Number, &number, TAG_END);
  356.                     cycledata[index].totalm = number;
  357.                 }
  358.  
  359.                 // Redraw gadgets to show updates
  360.                 GT_BeginRefresh(mywin);
  361.                 GT_EndRefresh(mywin, TRUE);
  362.  
  363.                 break;
  364.              case IDCMP_MENUPICK:
  365.                 // Menu chosen
  366.                 which_menu=MENUNUM(menu_number);
  367.                 which_item=ITEMNUM(menu_number);
  368.  
  369.                 while( menu_number != MENUNULL )
  370.                 {
  371.                     /* Get the address of the item: */
  372.                     item = (struct MenuItem *) ItemAddress( mainmenustrip, menu_number );
  373.  
  374.                     /* Check which item was selected: */
  375.                     if( which_menu == 0 )
  376.                     {
  377.                         if( which_item == 0 )
  378.                         {
  379.                             // If no records, don't ask to overwrite them
  380.                             if(records.recs[0] > 0)
  381.                                 answer = EasyRequest(NULL, &overwrite, NULL);
  382.                             else
  383.                                 answer = 1;
  384.  
  385.                             if(answer == 1)
  386.                             {
  387.                                 // new selected
  388.                                 index = 0;
  389.                                 records.recs[0] = 0;
  390.  
  391.                                 // Clear array of records
  392.                                 for(count=0; count < TRIPS-1; count++)
  393.                                 {
  394.                                     strcpy(cycledata[count].destination, space);
  395.                                     strcpy(cycledata[count].date, space2);
  396.  
  397.                                     cycledata[count].cycledist1 = 0;
  398.                                     cycledata[count].cycledist2 = 0;
  399.                                     cycledata[count].cycleouth = 0;
  400.                                     cycledata[count].cycleoutm = 0;
  401.                                     cycledata[count].cyclebackh = 0;
  402.                                     cycledata[count].cyclebackm = 0;
  403.                                     cycledata[count].train = FALSE;
  404.                                     cycledata[count].trainouth = 0;
  405.                                     cycledata[count].trainoutm = 0;
  406.                                     cycledata[count].trainbackh = 0;
  407.                                     cycledata[count].trainbackm = 0;
  408.                                     cycledata[count].totalh = 0;
  409.                                     cycledata[count].totalm = 0;
  410.                                     cycledata[count].changed = FALSE;
  411.                                 }
  412.  
  413.                                 // Clear gadgets
  414.                                 GT_SetGadgetAttrs(my_gads[MYGAD_RECCOUNT], mywin, NULL, GTNM_Number, 1, TAG_END);
  415.                                 GT_SetGadgetAttrs(my_gads[MYGAD_DESTGAD], mywin, NULL, GTST_String, cycledata[0].destination, TAG_END);
  416.                                 GT_SetGadgetAttrs(my_gads[MYGAD_DATEGAD], mywin, NULL, GTST_String, cycledata[0].date, TAG_END);
  417.                                 GT_SetGadgetAttrs(my_gads[MYGAD_DIST1], mywin, NULL, GTIN_Number, 0, TAG_END);
  418.                                 GT_SetGadgetAttrs(my_gads[MYGAD_DIST2], mywin, NULL, GTIN_Number, 0, TAG_END);
  419.                                 GT_SetGadgetAttrs(my_gads[MYGAD_CYCLEOUTH], mywin, NULL, GTIN_Number, 0, TAG_END);
  420.                                 GT_SetGadgetAttrs(my_gads[MYGAD_CYCLEOUTM], mywin, NULL, GTIN_Number, 0, TAG_END);
  421.                                 GT_SetGadgetAttrs(my_gads[MYGAD_CYCLEBACKH], mywin, NULL, GTIN_Number, 0, TAG_END);
  422.                                 GT_SetGadgetAttrs(my_gads[MYGAD_CYCLEBACKM], mywin, NULL, GTIN_Number, 0, TAG_END);
  423.                                 GT_SetGadgetAttrs(my_gads[MYGAD_TRAINTICK], mywin, NULL, GTCB_Checked, FALSE, TAG_END);
  424.                                 GT_SetGadgetAttrs(my_gads[MYGAD_TRAINOUTH], mywin, NULL, GTIN_Number, 0, TAG_END);
  425.                                 GT_SetGadgetAttrs(my_gads[MYGAD_TRAINOUTM], mywin, NULL, GTIN_Number, 0, TAG_END);
  426.                                 GT_SetGadgetAttrs(my_gads[MYGAD_TRAINBACKH], mywin, NULL, GTIN_Number, 0, TAG_END);
  427.                                 GT_SetGadgetAttrs(my_gads[MYGAD_TRAINBACKM], mywin, NULL, GTIN_Number, 0, TAG_END);
  428.                                 GT_SetGadgetAttrs(my_gads[MYGAD_TOTTIMEH], mywin, NULL, GTIN_Number, 0, TAG_END);
  429.                                 GT_SetGadgetAttrs(my_gads[MYGAD_TOTTIMEM], mywin, NULL, GTIN_Number, 0, TAG_END);
  430.                             }
  431.                         }
  432.                         if( which_item == 1 )
  433.                         {
  434.                             // If no records, don't ask to overwrite them
  435.                             if(records.recs[0] > 0)
  436.                                 answer = EasyRequest(NULL, &overwrite, NULL);
  437.                             else
  438.                                 answer = 1;
  439.  
  440.                             if(answer == 1)
  441.                             {
  442.                                 // load selected
  443.                                 result = load(mywin, my_gads);
  444.                                 if(result == 0)
  445.                                 {
  446.                                     // Display requester - Error while loading
  447.                                     EasyRequest(NULL, &loadfail, NULL);
  448.                                 }
  449.                                 else
  450.                                     index = 0;
  451.                             }
  452.                         }
  453.                         if( which_item == 2 )
  454.                         {
  455.                             // save selected
  456.                             result = save();
  457.                             if(result == 0)
  458.                             {
  459.                                 // Display Requester - Error while saving
  460.                                 EasyRequest(NULL, &savefail, NULL);
  461.                             }
  462.                         }
  463.                         if( which_item == 3 )
  464.                         {
  465.                             // about selected
  466.                             about_alert();
  467.                         }
  468.                         if( which_item == 4 )
  469.                         {
  470.                             terminated = TRUE;
  471.                         }
  472.                     }
  473.                     // Search menu
  474.                     if( which_menu == 1 )
  475.                     {
  476.                         if( which_item == 0 )
  477.                         {
  478.                             // Create & open input window
  479.  
  480.                 // Code removed for copyright reasons
  481.                         }
  482.                         if( which_item  == 1 )
  483.                         {
  484.                             // Display requester
  485.                             EasyRequest(NULL, ¬inuse, NULL);
  486.                         }
  487.             }
  488.            
  489.                     /* Get the following item's menu number: */
  490.                     menu_number = item->NextSelect;
  491.                 }
  492.                 break;
  493.             case IDCMP_CLOSEWINDOW:
  494.                 terminated = TRUE;
  495.                 break;
  496.             case IDCMP_REFRESHWINDOW:
  497.                 /* With GadTools, the application must use GT_BeginRefresh()
  498.                 ** where it would normally have used BeginRefresh()
  499.                 */
  500.                 GT_BeginRefresh(mywin);
  501.                 GT_EndRefresh(mywin, TRUE);
  502.                 break;
  503.             }
  504.         }
  505.     }
  506. }
  507.  
  508.